#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libosd/osd_lib.h>

#include "menus_root.h"
#include "win_com.h"


rootmenuhandle_t rootwinpool[] /*__attribute__((section(".flash")))*/= 
{        
#if 0//ChengYu@20140217, factory mode implement, Change the main menu handle
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_MENU,	FALSE,  (POBJECT_HEAD)&g_win_mainmenu},
#endif
#ifdef _INVW_JUICE   

	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_0,		TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_1,		TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_2,		TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_3,		TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_4,		TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_5,		TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_6,		TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_7,		TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_8,		TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_9,		TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_ENTER,	FALSE,  (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_EPG,		FALSE,  (POBJECT_HEAD)&g_win_inviewinput},
       {CTRL_MSG_SUBTYPE_KEY,   V_KEY_UP,		TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_DOWN,	TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_C_UP,	TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_C_DOWN,	TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_P_UP,	TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_P_DOWN,	TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	//{CTRL_MSG_SUBTYPE_KEY,   V_KEY_F_UP,	TRUE,   (POBJECT_HEAD)&g_win_inviewinput}, 	//chunpin V+v- mapping to fav+-
	//{CTRL_MSG_SUBTYPE_KEY,   V_KEY_F_DOWN,	TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	//{CTRL_MSG_SUBTYPE_KEY,   V_KEY_TVRADIO,	TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_INFOR,	FALSE,  (POBJECT_HEAD)&g_win_inviewinput},
	//{CTRL_MSG_SUBTYPE_KEY,   V_KEY_RECALL,	FALSE,  (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_LEFT,	TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_RIGHT,	TRUE,   (POBJECT_HEAD)&g_win_inviewinput},

	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_F_DOWN,	TRUE,   (POBJECT_HEAD)&g_win_volume},  //chunpin V+v- mapping to fav+-
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_F_UP,	TRUE,   (POBJECT_HEAD)&g_win_volume},


	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_FAV,	TRUE,   (POBJECT_HEAD)&g_win_inviewinput},
#endif
#ifdef _INVW_JUICE   
#else
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_UP,		TRUE,   (POBJECT_HEAD)&g_win_progname},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_DOWN,	TRUE,   (POBJECT_HEAD)&g_win_progname},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_C_UP,	TRUE,   (POBJECT_HEAD)&g_win_progname},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_C_DOWN,	TRUE,   (POBJECT_HEAD)&g_win_progname},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_P_UP,	TRUE,   (POBJECT_HEAD)&g_win_progname},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_P_DOWN,	TRUE,   (POBJECT_HEAD)&g_win_progname},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_F_UP,	TRUE,   (POBJECT_HEAD)&g_win_progname},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_F_DOWN,	TRUE,   (POBJECT_HEAD)&g_win_progname},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_TVRADIO,	TRUE,   (POBJECT_HEAD)&g_win_progname},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_INFOR,	FALSE,  (POBJECT_HEAD)&g_win_progname},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_RECALL,	FALSE,  (POBJECT_HEAD)&g_win_progname},
#endif

#ifdef _INVW_JUICE   
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_TVRADIO,	TRUE,  (POBJECT_HEAD)&g_win_progname},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_RECALL,	FALSE,  (POBJECT_HEAD)&g_win_progname},
#endif

#ifdef _INVW_JUICE  
#else
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_0,		TRUE,   (POBJECT_HEAD)&g_win_proginput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_1,		TRUE,   (POBJECT_HEAD)&g_win_proginput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_2,		TRUE,   (POBJECT_HEAD)&g_win_proginput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_3,		TRUE,   (POBJECT_HEAD)&g_win_proginput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_4,		TRUE,   (POBJECT_HEAD)&g_win_proginput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_5,		TRUE,   (POBJECT_HEAD)&g_win_proginput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_6,		TRUE,   (POBJECT_HEAD)&g_win_proginput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_7,		TRUE,   (POBJECT_HEAD)&g_win_proginput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_8,		TRUE,   (POBJECT_HEAD)&g_win_proginput},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_9,		TRUE,   (POBJECT_HEAD)&g_win_proginput},

	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_LEFT,	TRUE,   (POBJECT_HEAD)&g_win_volume},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_RIGHT,	TRUE,   (POBJECT_HEAD)&g_win_volume},
#endif	
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_V_DOWN,	TRUE,   (POBJECT_HEAD)&g_win_volume},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_V_UP,	TRUE,   (POBJECT_HEAD)&g_win_volume},

#ifdef _INVW_JUICE   
#else
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_ENTER,	FALSE,   (POBJECT_HEAD)&g_win_light_chanlist},
#endif	
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_LIST,	FALSE,   (POBJECT_HEAD)&g_win_light_chanlist},

//#ifndef HDTV_SUPPORT
//#if (SYS_CHIP_MODULE !=ALI_S3602)
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_ZOOM,	FALSE,   (POBJECT_HEAD)&g_win_zoom},	
//#endif
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_FIND,	FALSE,   (POBJECT_HEAD)&g_win_find},	
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_AUDIO,	FALSE,   (POBJECT_HEAD)&g_win_audio},

	
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_SLEEP,	FALSE,   (POBJECT_HEAD)&g_win_sleeptimer},
#ifdef _INVW_JUICE   
#else
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_EPG,		FALSE,   (POBJECT_HEAD)&g_win_epg},
#endif
        
#if(SUBTITLE_ON == 1)
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_SUBTITLE,		FALSE,   (POBJECT_HEAD)&g_cnt_subtitle},
#endif

#ifdef CC_BY_OSD		//vicky20110210
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_BLUE,	FALSE,   (POBJECT_HEAD)&g_win_closedcaption},
#endif
/*#if(ISDBT_CC == 1) //Martin@20150129
		{CTRL_MSG_SUBTYPE_KEY,   V_KEY_RED,	FALSE,   (POBJECT_HEAD)&g_win_cc},
#endif*/

#ifdef _INVW_JUICE   
#else
	#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_OFF)//ChengYu@20131014, disable change group function
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_FAV,		FALSE,   (POBJECT_HEAD)&g_win_light_chanlist},
	#else
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_SAT,		FALSE,   (POBJECT_HEAD)&g_win_satfav_list},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_FAV,		FALSE,   (POBJECT_HEAD)&g_win_satfav_list},
#endif
#endif

#ifdef AV_DELAY_SUPPORT
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_MP,		FALSE,   (POBJECT_HEAD)&win_av_delay_con},	
#else
#if (SYS_CHIP_MODULE !=ALI_S3602)
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_MP,		FALSE,   (POBJECT_HEAD)&g_cnt_multiview},	
#endif
#endif

#ifdef HDTV_SUPPORT
#if 0//def SD_PVR
    {CTRL_MSG_SUBTYPE_KEY,   V_KEY_VIDEO_FORMAT,FALSE,(POBJECT_HEAD)&g_win_PALNTSC},
#else
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_VIDEO_FORMAT,FALSE,(POBJECT_HEAD)&g_win_hdtv_mode},
#endif   
#endif

#ifdef DVR_PVR_SUPPORT
#ifndef DISABLE_MP_PVR
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_RECORD,  TRUE,   (POBJECT_HEAD)&g_win_pvr_ctrl},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_FF,   	TRUE,   (POBJECT_HEAD)&g_win_pvr_ctrl},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_FB,   	TRUE,   (POBJECT_HEAD)&g_win_pvr_ctrl},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_SLOW,   	TRUE,   (POBJECT_HEAD)&g_win_pvr_ctrl},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_B_SLOW,	TRUE,   (POBJECT_HEAD)&g_win_pvr_ctrl},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_PLAY,   	TRUE,   (POBJECT_HEAD)&g_win_pvr_ctrl},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_PAUSE,   TRUE,   (POBJECT_HEAD)&g_win_pvr_ctrl},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_STOP,   	TRUE,   (POBJECT_HEAD)&g_win_pvr_ctrl},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_PREV,   	TRUE,   (POBJECT_HEAD)&g_win_pvr_ctrl},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_NEXT,   	TRUE,   (POBJECT_HEAD)&g_win_pvr_ctrl},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_PVR_INFO,FALSE,   (POBJECT_HEAD)&g_win_pvr_ctrl},
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_DVRLIST, FALSE,   (POBJECT_HEAD)&g_win_record},
#endif	
#endif
#ifdef USB_MP_SUPPORT
#ifndef DISABLE_MP_PVR
	{CTRL_MSG_SUBTYPE_KEY,   V_KEY_FILELIST,FALSE,   (POBJECT_HEAD)&g_win_usb_filelist},
#endif
#endif
#ifdef MULTIFEED_SUPPORT
    {CTRL_MSG_SUBTYPE_KEY, V_KEY_PIP_LIST, FALSE, (POBJECT_HEAD)&g_win_multifeed},
#endif
};


BOOL menus_find_root(UINT32 msgType,UINT32 msgCode,BOOL* bFlag,POBJECT_HEAD* winhandle)
{
	int i,n;
	rootmenuhandle_t *roothandle;
	UINT32	vkey;
	
	ap_hk_to_vk(0, msgCode, &vkey);
#ifdef _INVW_JUICE   
	if (vkey == V_KEY_MENU)
	{
		ap_osd_int_restore();
	}
#endif
	
	n = sizeof(rootwinpool)/sizeof(rootwinpool[0]);
	for(i=0;i<n;i++)
	{
		roothandle = &rootwinpool[i];
		if(roothandle->msgType == msgType 
			&& roothandle->msgCode == vkey)
		{
			*bFlag = roothandle->processMsg;//bflag;
			*winhandle = roothandle->root;
			return TRUE;
		}
	}

	*winhandle = NULL;

	return FALSE;
}

